<?php
class File extends Object{
	
	var $dirname;
    var $basename;
    var $extension;
   	var $filename;
   	var $file;
 

	function __construct($file=null){
		$this->file=$file;
	}
	
	function parseFile($file){
		$parse=false;
		if($this->fileReadable($file)){
			$parse=path_parts($file);
			$this->arrayToObject($parse);
		}
		return $parse;
	}
	
	function fileExists($file){
		$exists=false;
		if($this->isFile($file)){
			if(file_exists  ( $file )){
				$exists=true;
			}
		}
		return $exists;
	}
	
	function fileReadable($file=null){
		$readable=false;
		if($file==null)
			$file=$this->file;
		if($this->isFile($file)){
			if(is_readable ( $file )){
				$readable=true;
			}
		}
		return $readable;
	}
	
	function isFile($file){
		$isFile=false;
		if($this->isString($file)){
			if(is_file ( $file )){
				$isFile=true;
			}
		}
		return $isFile;
	}
	
	
	function fileLineToArray($file){
		$array=array();
		if($this->isFile($file)){	
			$handle = @fopen($file, "r");
			$array=array();
			if ($handle) {
			    while (!feof($handle)) {
			        $buffer = fgets($handle, 4096);
			        if(strlen($buffer ))
			        	$array[]=$buffer;
			    }
			    fclose($handle);
			}
		}
		return $array;
	}
	
	
	function force_download_string($contents, $name) {
		$filesize = strlen($contents);
		ini_set('zlib.output_compression', 'Off');
		/* IE FIX : FireFox Compatible */
		header("Content-Type: application/application/octet-stream\n");
		header("Content-Disposition: attachment; filename=\"$name\"");
		/* Print It */
		echo $contents;
		exit;
	}
	
	
	
	function uploadFileCheck($file,$maxFile,$allowed){
		if($file['size']>$maxFile)
			return false;
		if(array_search($this->getType($file['name']),$allowed)===false)
			return false;
		return true;
	}
	
	function getType($name_str){
		if(strripos  ( $name_str  , '.' )===false) return fasle;
		$type=explode(".",$name_str);
		if(!is_array($type)) return false;
		$type=end($type);
		return strtolower($type);
	}
	
	/*
	 * copied of net need to alter
	 */
	function uploadMoveFile($file,$base){;
		if(!is_dir($base)) return false;
		$target_path = $base . basename( $file['name']); 
		
		if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
		    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
		    " has been uploaded";
		} else{
		    echo "There was an error uploading the file, please try again!";
		}
	}
	
	
}
?>